package svc

import (
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"module_demo/user-service/api/internal/config"
	"module_demo/user-service/api/internal/db"
)

type ServiceContext struct {
	Config config.Config
	Mysql  sqlx.SqlConn //使用mysql
	Redis  *redis.Redis //使用redis
}

func NewServiceContext(c config.Config) *ServiceContext {
	mysql := db.NewMysql(c.MysqlConfig)     //初始化mysql
	redisConn := db.NewRedis(c.RedisConfig) //初始化redis
	return &ServiceContext{
		Config: c,
		Mysql:  mysql,     //注入
		Redis:  redisConn, //注入
	}
}
